import 'dart:io';

import 'package:flutter/material.dart';
import 'package:work/message.dart';
import 'package:work/news.dart';
import 'package:work/second.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '工作任务',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: '主页面'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var _scaffoldkey = GlobalKey<ScaffoldState>();

  void close() {
    exit(0);
  }

  void flush() {
    final snackBar = SnackBar(
      content: Text('Yay, A SnackBar!'),
      action: SnackBarAction(
        label: 'Undo',
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return SecondPage();
          }));
        },
      ),
    );
    _scaffoldkey.currentState.showSnackBar(snackBar);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        key: _scaffoldkey,
        appBar: AppBar(
          leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: close),
          actions: [
            IconButton(
                icon: Icon(
                  Icons.autorenew,
                  color: Colors.white,
                ),
                onPressed: flush)
          ],
          title: Text(widget.title),
        ),
        body: Center(
          child: Column(
            children: [
              Container(
                color: Colors.amber,
                child: Row(
                  children: [
                    Container(
                        child: Text("网络请求实例",
                            style: TextStyle(
                                color: Colors.deepPurple,
                                fontSize: 14,
                                fontWeight: FontWeight.w500)),
                        margin: const EdgeInsets.only(
                            top: 8.0, left: 16, bottom: 8))
                  ],
                ),
              ),
              MessagePage(),
              Container(
                height: 0.5,
                color: Colors.deepPurple,
              ),
              News()
            ],
          ),
        ));
  }
}
